package com.lft04.callable;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Function: 		A {@code TestMoreThreadDownloader} object With Some FUNCTION.<br/>
 * Reason:   		ADD REASON.<br/>
 * Date:            2021-01-26 19:48<br/>
 * <p>
 * Class Name:      TestMoreThreadDownloader<br/>
 * Package Name:    com.lft.thread<br/>
 * @author Laifengting / E-mail:laifengting@foxmail.com
 * @version 1.0.0
 * @since JDK 8
 */
public class TestMultiThreadDownloader {
	public static void main(String[] args) {
		// 第三步：创建自定义线程类
		LftThread lftThread1 = new LftThread("https://gimg2.baidu.com/image_search/src=http%3A%2F" +
													 "%2Fattach.bbs.miui" +
													 ".com%2Fforum%2F201305%2F30" +
													 "%2F220025pxfkhykvkgkvuktq" +
													 ".jpg&refer=http%3A%2F%2Fattach" +
													 ".bbs" +
													 ".miui.com&app=2002&size=f9999," +
													 "10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1614253757&t" +
													 "=170059627f559cac4ed774fe28a3c9f4",
											 "01" +
													 ".jpg");
		LftThread lftThread2 = new LftThread("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg" +
													 ".pconline.com" +
													 ".cn%2Fimages%2Fupload%2Fupc%2Ftx%2Fsoftbbs%2F1003" +
													 "%2F07%2Fc0" +
													 "%2F3134443_1267900790753_1024x1024soft" +
													 ".jpg&refer=http%3A%2F%2Fimg.pconline.com" +
													 ".cn&app=2002&size=f9999," +
													 "10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1614253758&t" +
													 "=6ac33964b0a9b5b4e7bf494777cc1ea7",
											 "02.jpg");
		LftThread lftThread3 = new LftThread("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fattach.bbs.miui" +
													 ".com%2Fforum%2F201310%2F19%2F235439yh04c010wm0qrk5d" +
													 ".jpg&refer=http%3A%2F%2Fattach.bbs" +
													 ".miui" +
													 ".com&app=2002&size=f9999," +
													 "10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1614253760&t" +
													 "=24c05fcc7cab6ef0a1f296fef38bbaea",
											 "03.jpg");
		// 第四步：创建执行服务
		ExecutorService service = Executors.newFixedThreadPool(3);
		
		// 第五步：提交执行
		Future<Boolean> result1 = service.submit(lftThread1);
		Future<Boolean> result2 = service.submit(lftThread2);
		Future<Boolean> result3 = service.submit(lftThread3);
		
		// 第六步：获取结果
		try {
			Boolean b1 = result1.get();
			Boolean b2 = result2.get();
			Boolean b3 = result3.get();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		// 第七步：关闭服务
		service.shutdownNow();
		
	}
}
